package com.mango.leet.code.week2.game379;

import java.util.PriorityQueue;

/**
 * https://leetcode.cn/contest/weekly-contest-379/problems/maximum-area-of-longest-diagonal-rectangle/
 * @Author: mango
 * @Date: 2024/1/7 10:33
 */
public class LC100170 {
    public static int areaOfMaxDiagonal(int[][] dimensions) {
        PriorityQueue<int[]> queue = new PriorityQueue<>(2, (o1, o2)->{
            int b31 = b3(o1[0], o1[1]);
            int b32 = b3(o2[0], o2[1]);
            if (b31 == b32) {
                return -Integer.compare(o1[0] * o1[1], o2[0] * o2[1]);
            } else {
                return -Integer.compare(b31, b32);
            }
        });
        for (int i = 0; i < dimensions.length; i++) {
            queue.offer(dimensions[i]);
        }
        int[] one = queue.peek();
        return one[0] * one[1];
    }

    public static int b3(int b1, int b2) {
        return b1*b1 + b2*b2;
    }
    public static void main(String[] args) {
        int[][] dimesions = {
                {9,3},
                {8,6}
        };
        System.out.println(areaOfMaxDiagonal(dimesions));
    }
}
